﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTcms.BLL;
using DTcms.Web.Libs.WeiXin.business;
using DTcms.Web.Libs.WeiXin.lib;

namespace DTcms.Web.WxSdjs
{
    public partial class Pay : System.Web.UI.Page
    {
        public static string payType = string.Empty;
        public static string wxJsApiParam { get; set; } //H5调起JS API参数

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string orderId = Request["orderId"] ?? string.Empty;
                string youHuiId = Request["youHuiId"] ?? string.Empty;

                pao_order orderBll = new pao_order();
                payType = orderId.Substring(0, 1);

                long orderIdLong = Convert.ToInt64(orderId.Substring(1));
                DTcms.Model.pao_order order = orderBll.GetModel(orderIdLong);

                string typeName = order.pao_w_typename;
                decimal? orderMoney = order.pao_money +
                    order.pao_wipin_money -
                    order.pao_youhui_money +
                    order.pao_toubao_money;

                if (orderMoney == null)
                    orderMoney = 0;
                int totalFee = (int)(orderMoney.Value * 100);
                //totalFee = 1;

                string openId = Session["openid"].ToString();

                JsApiPay jsApiPay = new JsApiPay(this);
                jsApiPay.openid = openId;
                jsApiPay.total_fee = totalFee;

                try
                {
                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(orderId, typeName);
                    wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数                                 
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    throw;
                }




            }

        }

    }
}